package com.agile.leetcode.sms;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;

import java.util.HashMap;
import java.util.Set;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/11/26 16:45
 */
public class RonglianSms {
    private static final String ACCOUNT_SID = "8a216da87d55f9cc017d5b5fa3cb0121";
    private static final String AUTH_TOKEN = "8d42af2dd7494517a8293feec7ccb356";
    private static final String APPID = "8a216da87d55f9cc017d5b5fa4e40128";
    private static final String URL = "app.cloopen.com";
    private static final String PORT = "8883";

    public static void main(String[] args) {
        CCPRestSmsSDK ccpRestSmsSDK = new CCPRestSmsSDK();
        ccpRestSmsSDK.setAccount(ACCOUNT_SID, AUTH_TOKEN);
        ccpRestSmsSDK.setAppId(APPID);
        ccpRestSmsSDK.setBodyType(BodyType.Type_JSON);
        ccpRestSmsSDK.init(URL, PORT);
        // 数据，有效分钟数
        String[] datas = {"6666", "5"};
        HashMap<String, Object> result = ccpRestSmsSDK.sendTemplateSMS("15723315609", "1", datas);
        System.out.println(result);
        if ("000000".equals(result.get("statusCode"))) {
            // 正常返回输出data包体信息（map）
            HashMap<String, Object> data = (HashMap<String, Object>) result.get("data");
            Set<String> keySet = data.keySet();
            for (String key : keySet) {
                Object object = data.get(key);
                System.out.println(key + " = " + object);
            }
        } else {
            //异常返回输出错误码和错误信息
            System.out.println("错误码=" + result.get("statusCode") + " 错误信息= " + result.get("statusMsg"));
        }
    }
}
